﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.Helpers;

namespace rndbuddy
{
    static class BotController
    {
        public static void use_gb2()
        {
            ProfileHandler.LoadBotBase("Gatherbuddy2");
            ProfileHandler.get_profile();
            ProfileHandler.TreeAction("start");
        }

        public static void use_pb()
        {
            ProfileHandler.LoadBotBase("ProfessionBuddy");
            ProfileHandler.get_profile();
            ProfileHandler.TreeAction("start");
        }

        public static bool is_gather_botbase()
        {
            if (is_gatherbuddy())
                return true;

            if (is_professionbuddy())
                return true;

            if (is_mixed_gb2())
                return true;

            return false;
        }

        public static bool is_professionbuddy()
        {
            if (TreeRoot.Current.Name.Contains("Profession"))
                return true;
            return false;
        }

        public static bool is_gatherbuddy()
        {
            if (TreeRoot.Current.Name.Contains("Gather"))
                return true;
            return false;
        }

        public static bool is_questbot()
        {
            if (TreeRoot.Current.Name.Contains("Quest"))
                return true;
            return false;
        }
        public static bool is_mixed_gb2()
        {
            if (TreeRoot.Current.Name.Contains("Mixed") && settings.use_mixed_mode_for_gathering)
                return true;
            return false;
        }

        public static bool is_manual_botbase()
        {
            if (TreeRoot.Current.Name.Contains("Tyrael"))
                return true;
            if (TreeRoot.Current.Name.Contains("Lazy"))
                return true;
            return false;
        }

        public static bool are_there_reloggers()
        {
            var plist = Process.GetProcesses().Where(
                    p =>
                        p.ProcessName == "ARelog" ||
                        p.ProcessName == "HBRelog"
                    )
                        .ToList();
            if (plist.Count > 0)
                return true;
            return false;
        }

        public static bool is_gatherbot_on_duty()
        {
            if (BotController.is_gatherbuddy())
                return true;

            if (is_professionbuddy())
            {
                var secondBot = BotManager.Instance.Bots.Values.ElementAt(1);
                if (secondBot.Name.Contains("Gather"))
                    return true;
            }

            return false;
        }

        public static string get_botbase_status()
        {
            if (is_questbot())
                return (StyxWoW.Me.Experience * 100 / StyxWoW.Me.NextLevelExperience).ToString() + @"% of Level";
            if (is_gatherbuddy())
              return ProfileHandler.calc_and_return_nph().ToString() + " NPH";
            if (is_gatherbot_on_duty())
                return ProfileHandler.calc_and_return_nph().ToString() + " NPH";

            return "no status";
        }
    }
}
